// 创建用户表,或注释掉读SQL语句初始化加载
const conn = require('../mysql');
const fs = require('fs');
const path = require("path");
const DirPath = path.join(__dirname, ".","sql");
conn.getConnection((err, conn) => {
    if (err) {
        console.log("MySQL连接失败,失败信息为：" + err);
    } else {
        console.log("连接成功");
        fs.readFile(DirPath + '/user.sql', 'utf8', (err, data) => {
            if (err) return;
            conn.query(data, (err, result) => {
                if (err) throw err;
                console.log("建表成功");
            })
        });
        fs.readFile(DirPath + '/article.sql', 'utf8', (err, data) => {
            if (err) return;
            conn.query(data, (err, result) => {
                if (err) throw err;
                console.log("建表成功");
            })
        });
        fs.readFile(DirPath + '/articletype.sql', 'utf8', (err, data) => {
            if (err) return;
            conn.query(data, (err, result) => {
                if (err) throw err;
                console.log("建表成功");
            })
        })
    }
})
module.exports=conn;